package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.util.OpenPlatformEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class WechatUserPhoneBindRequest extends Request {

	private Integer userId;
	
	private String openId;
	
	private String phone;
	
	private Integer openPlatformId;
	
	private String ip;
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.userId = requestInfo.getIntParameter(ApiUrlParamEnum.userId.getParamName(), 0);
		this.openId = requestInfo.getParameter(ApiUrlParamEnum.openId.getParamName(), "");
		this.phone = requestInfo.getParameter(ApiUrlParamEnum.phone.getParamName(), "");
		this.openPlatformId = requestInfo.getIntParameter(ApiUrlParamEnum.openPlatformId.getParamName(), OpenPlatformEnum.WECHAT_MALL.getId());
		this.ip = requestInfo.getParameter(ApiUrlParamEnum.ip.getParamName(), requestInfo.getUserIp());
		if (userId < 1) {
			throw new RequestIllegalException("error userId: " + userId);
		}
		if (StringUtil.isEmpty(openId)) {
			throw new RequestIllegalException("error openId: " + openId);
		}
		if (!StringUtil.isMobilePhone(phone)) {
			throw new RequestIllegalException("error phone: " + phone);
		}
	}

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}
	
	public Integer getOpenPlatformId() {
		return openPlatformId;
	}

	public void setOpenPlatformId(Integer openPlatformId) {
		this.openPlatformId = openPlatformId;
	}

	public String getIp() {
		return this.ip;
	}
	
	public void setIp( String ip ) {
		this.ip = ip;
	}

}
